// @ts-ignore
import request from './request.js'

export async function getCategories() {
  return await request.get('/categories')
}

export async function getCategoryPage(params?: any) {
  return await request.get('/category/page', { params })
}

export async function getProductList(params?: any) {
  return await request.get('/product/pages', { params })
}

export async function getRecommendProducts() {
  return await request.get('/products/recommend')
}

export async function getProductDetail(id: string) {
  return await request.get(`/product/${id}`)
}

// 新增商品（上架）
export async function addProduct(data: any) {
  return await request.post('/product', data)
}

// 下架商品（删除）
export async function deleteProduct(id: number|string) {
  return await request.delete(`/product/${id}`)
}

// 修改商品
export async function updateProduct(data: any) {
  return await request.put('/product', data)
}

// 获取二级分类
export async function getSecondaryCategories(parentId: number) {
  return request({
    url: `/secondary/${parentId}`,
    method: 'get',
  })
}
